package cn.edu.ctbu.demo2.service.impl;

import cn.edu.ctbu.demo2.domain.Course;
import cn.edu.ctbu.demo2.domain.Score;
import cn.edu.ctbu.demo2.repository.CourseRepository;
import cn.edu.ctbu.demo2.repository.ScoreRepository;
import cn.edu.ctbu.demo2.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;


@Service
public class CourseimplService implements CourseService {
    @Autowired
    private CourseRepository courseRepository;
    public Course Insert(Course course){
        courseRepository.save(course);
        return course;
    }

    public Page<Course> findAll(Pageable pageable){
        return courseRepository.findAll(pageable);
    };

    public Page<Course> findAll(Example<Course> course, Pageable pageable){
        return courseRepository.findAll(course,pageable);
    }
    public Course getById(Integer id){

        return courseRepository.findById(id).orElse(null);
    }

    public Course update(Course course){
        courseRepository.save(course);
        return course;
    }

    public void delete(Integer id){
        Course course=new Course();
        course.setId(id);
        courseRepository.delete(course);
    }

}
